package org.edu.modules.stu.common.service.impl;

import org.edu.common.base.BasePageDto;
import org.edu.common.base.BaseServiceImpl;
import org.edu.common.utils.ConvertUtils;
import org.edu.common.base.BaseServiceImpl;
import org.edu.modules.stu.common.mapper.VeBaseBanjiMapper;
import org.edu.modules.stu.common.entity.VeBaseBanji;
import org.edu.modules.stu.common.dto.VeBaseBanjiDto;
import org.edu.modules.stu.common.mapper.VeBaseTeacherMapper;
import org.edu.modules.stu.common.service.VeBaseBanjiService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;



/**
 * 实现类
 */
@Service
public class VeBaseBanjiServiceImpl extends BaseServiceImpl<VeBaseBanji, VeBaseBanjiMapper> implements VeBaseBanjiService {

    @Autowired
    private VeBaseBanjiMapper veBaseBanjiMapper;


    public IPage<VeBaseBanjiDto> pageDto(BasePageDto page, @Param(Constants.WRAPPER) Wrapper queryWrapper){
        return mapper.pageDto(page,queryWrapper);
    }
    /**
    * 查询实体类
    */
    public VeBaseBanjiDto findDtoById(String id) {
        VeBaseBanji entity = super.findById(id);
        VeBaseBanjiDto dto = ConvertUtils.convertToDto(entity, VeBaseBanjiDto.class);
        return dto;
    }

    /**
    * 新增或者修改
    */
    public void insertOrUpdate(VeBaseBanjiDto dto,Boolean isAdd){
        if(isAdd){
            super.insert(dto);
        }else{
            super.update(dto);
        }
    }

    @Override
    public List<VeBaseBanji> listByTeacherId(String userId) {
        return veBaseBanjiMapper.listByTeacherId(userId);
    }

    @Override
    public void importExcel(List<Map<String, Object>> mapList){
        for (Map map: mapList) {
            VeBaseBanjiDto dto = new VeBaseBanjiDto();
//                            dto.setTerminalid ((String)map.get(0000));
                            dto.setXzbdm ((String)map.get("行政班代码"));
                            dto.setXzbmc ((String)map.get("行政班名称"));
                            dto.setNjdm ((String)map.get("年级代码"));
                            dto.setNjmc ((String)map.get("年级名称"));

//                            dto.setGradeid ((String)map.get(0000));
                            dto.setZydm ((String)map.get("专业代码"));
//                            dto.setSpecid ((String)map.get(0000));
                            dto.setJbny ((String)map.get("建班年月"));
                            dto.setRxnf ((String)map.get("入学年份"));
//                            dto.setBzruserid ((String)map.get(0000));
                            dto.setNansrs (Integer.parseInt(map.get("男生人数")+""));
                            dto.setNvsrs (Integer.parseInt(map.get("女生人数")+""));
                            dto.setZrs (Integer.parseInt(map.get("总人数（人数上限）")+""));
//                            dto.setBzuserid ((String)map.get(0000));
                            dto.setJxjh ((String)map.get("教学计划"));
//                            dto.setDepid ((String)map.get(0000));
//                            dto.setCampusid ((String)map.get(0000));
//                            dto.setJzid ((String)map.get(0000));
//                            dto.setJsid ((String)map.get(0000));
                            dto.setBysj (Integer.parseInt(map.get("毕业时间")+""));
                            dto.setListsort (Integer.parseInt(map.get("排序")+""));
                            dto.setStatus (1);
                            dto.setBystatus (Integer.parseInt(map.get("毕业班级状态，0=>未毕业，1=>毕业审核中， 2=>已毕业")+""));

            super.insert(dto);
        }

    }

}
